package com.caesar.Date.third;

import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;

/**
 * @author caesar
 * @date 2025/7/15
 * @Description:一段日期和一段时间-
 *              Period：日期间隔
 *              Duration：时间间隔
 * @apiNote
 */
public class TestPeriod {
    @Test
    public void test(){
        LocalDate today = LocalDate.now();
        LocalDate start = LocalDate.of(2025, 6, 25);
        Period period = Period.between(start, today);
        System.out.println(period);
        //P20D
        //P：表示 Period（时间段）的开始，是 "Period" 的缩写。
        //D：表示天数（Days）。
    }

    @Test
    public void test2(){
        LocalDate today = LocalDate.now();
        LocalDate birthday = LocalDate.of(2000, 5, 1);
        Period period = Period.between(birthday, today);
        System.out.println(period);
        //P25Y2M14D
    }

    @Test
    public void test3(){
        LocalTime now = LocalTime.now();
        LocalTime time = LocalTime.of(9, 50, 0);
        Duration duration = Duration.between(now, time);
        System.out.println(duration);//PT6M39.935055S
    }
}
